<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\ApiController;
use App\Http\Resources\OrderInfoResource;
use App\Repositories\Bonus\BonusTypeRepository;
use App\Repositories\Bonus\UserBonusRepository;
use App\Repositories\Category\CategoryRepository;
use App\Repositories\Goods\GoodsRepository;
use App\Repositories\Louxiaoer\LouxiaoerLandmarkRepository;
use App\Services\Bonus\BonusService;
use App\Services\Cart\CartService;
use App\Services\Category\CategoryService;
use App\Services\Goods\GoodsService;
use App\Services\Orders\CheckOutService;
use App\Services\Orders\OrderQueueService;
use App\Services\Orders\OrderService;

class OrderInfoController extends ApiController
{
    protected $orderService;

    protected $orderQueueService;

    protected $bonusService;

    protected $goodsService;

    protected $checkOutService;

    public function __construct(OrderService $orderService,
                                OrderQueueService $orderQueueService,
                                BonusService $bonusService,
                                GoodsService $goodsService,
                                CheckOutService $checkOutService)
    {
        $this->orderService = $orderService;
        $this->orderQueueService = $orderQueueService;
        $this->bonusService = $bonusService;
        $this->goodsService = $goodsService;
        $this->checkOutService = $checkOutService;


    }

    public function index(){
        $data  = $this->goodsService->getShoppingBag(6009,8);
        dump($data);
        exit;
        $data =  $this->bonusService->getUserBonus(6009,2);
        return $this->orderService->get38data();
//        $order_info = $this->orderService->getOrderById(772289);
//        $order_goods = $this->orderService->getGoodsList(772289);
//        if($order_info->isEmpty()){
//            return $this->failed('订单不存在');
//        }else{
//            return $this->success(new OrderInfoResource($order_info));
//        }
    }

    public function show(){
        $data = $this->orderService->getOrdersByUserId(1,10);
        return $data;
    }

    public function all(){
        $data = $this->orderService->getAllOrders(1);
        return $data;
    }

    public function test_queue(){
        $param = array();
        $param['user_id'] = 1;

        //队列检查
//        $this->orderQueueService->checkOrderQueue($param);

        $res = $this->orderService->orderInfoFormat($param);
        return $res;
    }

    public function test_bonus(){
//        $categoryService = new CategoryService(app(CategoryRepository::class));
//        return $categoryService->getAllSubCateId(57);

        $bonusService = new BonusService(
            app(BonusTypeRepository::class),
            app(UserBonusRepository::class),
            app(LouxiaoerLandmarkRepository::class),
            app(GoodsRepository::class),
            app(CategoryService::class)
        );

        $param = array();
        $param['order_id'] = 111;
        $param['user_id'] = 6009;
        $param['pay_log_id'] = 1;
        $param['get_time'] = gm_time();
        $param['deadline'] = gm_time()+7*24*3600;
        return $bonusService->useBonus(1163418,$param);
    }

    public function orderCheckOut(){
        $param = [];
        $param['user_id']= 6009;
        $param['bonus_id']= 171;
        $param['shopping_type'] = 1;
        $param['wid'] = 8;

        $res = $this->checkOutService->PrepareOrderSettlement($param);
        return $res;
    }
}
